<?php
class Login_Data_Loginform {
	
	/**
	 * form handler
	 * 
	 * @var $form
	 */
	public $form;
	
	/**
	 * constructor
	 */
	public function __construct(){
		
		$this->form = new Core_Driver_Firstform();
		
	}
	
	public function getLoginForm(){
		
		$article['form'] = "";
		$article['form'] .= $this->formStart();
		$article['form'] .= $this->hiddenInputLogin();
		$article['form'] .= $this->getDescription();
		$article['form'] .= "<ul>";
		$article['form'] .= $this->usernameInput();
		$article['form'] .= $this->passwordInput();
		$article['form'] .= "</ul>";
		$article['form'] .= "<div class=\"buttons\">";
		$article['form'] .= $this->submitForm();
		$article['form'] .= $this->endForm();
		$article['form'] .= "</div>";
		return $article;
	}
	
	/**
	 * return end form
	 */
	public function endForm(){
		
		return $this->form->endForm();
	
	}
	
	/**
	 * return submit button
	 */
	public function submitForm(){
		
		return $this->form->inputForm(
			array(
				"id" => "submit",
					"type" => "submit",
					"name" => "submit",
					"value" => LOGIN_FORM_SUBMIT_VALUE
			),
				null
		);
		
	}
	
	/**
	 * generate password field
	 * 
	 * @return string $inputPassword
	 */
	public function passwordInput(){
		
		$inputPassword = "<li>";
		
		$inputPassword .= $this->form->labelForm(
			array(
				"for" => "password"
			),
			LOGIN_FORM_PASSWORD
		);
		
		
		$inputPassword .= $this->form->inputForm(
			array(
				"id" => "password",
					"type" => "password",
					"name" => "password",
					"maxlength" => "20", 
					"placeholder" => LOGIN_FORM_PASSWORD_PLACEHOLDER
			),
				"required"
		);
		
		$inputPassword .= "</li>";
		
		return $inputPassword;
		
	}
	
	/**
	 * generate username field
	 * 
	 * @return string $usernameInput
	 */
	public function usernameInput(){
		
		$usernameInput = "<li>";
		
		$usernameInput .= $this->form->labelForm(
			array(
				"for" => "login"
			),
				LOGIN_FORM_USERNAME,
				null
				
		);
		
		$usernameInput .= $this->form->inputForm(
			array(
				"id" => "login",
					"type" => "text",
					"name" => "username",
					"maxlength" => "20",
					"placeholder" => LOGIN_FORM_USERNAME_PLACEHOLDER
			),
				"required autofocus"
		);
		
		$usernameInput .= "</li>";
		
		return $usernameInput;		
	}
	
	/**
	 * login form descrption
	 * @return string
	 */
	public function getDescription(){
		return '<p style="padding: 0 0 10px 0; text-align: center">'.LOGIN_FORM_DESCRIPTION.'</p>';
	}
	
	/**
	 * return hidden input
	 */
	public function hiddenInputLogin(){
		
		return $this->form->inputForm(
			array(
				"type" => "hidden",
					"name" => "hiddenInputLogin",
					"id" => "hiddenInputLogin",
					"value" => "true"
			),
				null
		);
		
	}
	
	/**
	 * return start form
	 */
	public function formStart(){
		
		return $this->form->startForm(
			array(
				"id" => "loginForm",
					"action" => SITE_ROOT."login.html",
					"method" => "post",
					"style" => "width: 50%"
			)
		);
		
	}
	
}